format

pure function format(args: anything...): text

Uses this text as a format string and returns the text obtained by substituting the specified arguments.

Supports many of the format specifiers found in other programming languages, including:

  • %s for text

  • %d for integers and big_integers in decimal (base 10) representation

  • %o for integers and big_integers in octal (base 8) representation

  • %x for integers and big_integers in hexadecimal (base 16) representation

  • %f for decimal (supports precision, e.g. %.2f for two decimal places)

  • %b for booleans (output in lower-case, i.e. true and false)

  • %B for booleans (output in upper-case, i.e. TRUE and FALSE)

Examples:

  • 'My integer is %d.'.format(123) returns 'My integer is 123.'.

  • 'See you...%10s.'.format('later') returns 'See you... later.'.

  • 'Earnings: daily=%f, weekly=%f, monthly=%f.'.format(312.45, 534.78, 2199.67) returns 'Earnings: daily=312.450000, weekly=534.780000, monthly=2199.670000.'.

  • ''%d %o %x'.format(14, 14, 14)' returns '14 16 e'.

If any format specifier is incompatible with the type of its corresponding argument, or if there are more specifiers requiring substitution than there are arguments, all format specifiers are left unsubstituted in the output text.

All format specifiers are also left unsubstituted in the output text when any argument is null, except when it matches the specifier is %s, in which case the text 'null' is substituted (assuming the other arguments and specifiers are correctly matched).

If there are more arguments than format specifiers, the extra arguments are ignored, but matched arguments are still substituted (assuming they match correctly).

Return

formatted text

Since

0.6.0

Parameters

args

Arguments referenced by the format specifiers in this format string. The number of arguments is variable and may be zero.